<?php
/**
 * Created by PhpStorm.
 * User: chuan
 * Date: 2014/11/23 0023
 * Time: 21:24
 */

function getPage($html)
{
    $page = '';
    foreach ($html->find('div[id=page] a') as $item) {
        $page = $item->innertext;
    }

    $number = findNum($page);
    if ($number == '') exit('分析页数时出错');

    p($number);
    return $number;
}

function findNum($str = '')
{
    $str = trim($str);
    if (empty($str)) {
        return '';
    }
    $reg = '/(\d{3}(\.\d+)?)/is';//匹配数字的正则表达式
    preg_match_all($reg, $str, $result);
    if (is_array($result) && !empty($result) && !empty($result[1]) && !empty($result[1][0])) {
        return $result[1][0];
    }
    return '';
}

function checkPermission()
{
    $filename = './file/';
    if (!is_writable($filename)) exit('file 目录不可写入，请检查权限！');
}

?>